This page last changed on Oct 27, 2006 by andrew.

Quartz provider supplies scheduling features to Mule. This provider is based on the great scheduler Quartz from OpenSymphony.

The javadoc for this transport provider can be found here. And the Source Xref can be found here

Quartz Connector properties

Property Description Default Required
factoryClassName The class name of the scheduler factory. You will usually not change this property. org.quartz.impl.StdSchedulerFactory No
factoryProperties a Properties object used to customize the scheduler factory.   No
factory You can give here an instance of org.quartz.SchedulerFactory if you have one.   No
scheduler The scheduler property can be set to an existing scheduler.   No

Quartz Endpoint properties

Property Description Default Required
cronExpression The cron expression to schedule events at specified dates / times.   One of cron or repeatInterval
repeatInterval The number of milliseconds between two events   One of cron or repeatInterval
repeatCount The number of events to be scheduled. This value defaults to -1 which means that the events will be scheduled indefinitely. -1 No
startDelay The number of milliseconds that will elapse before the first event is fired. 0 No
groupName The group name of the scheduled job mule No
jobGroupName The job group name of the scheduled job mule No

Additionally, other properties need to be set depending on the type of Job being used. The following describes the standard Mule Jobs and how to configure them.

Jobs

Mule provides a number of default Job implementations that help orchestrate scheduled events -

  • Mule Receiver Job - An inbound endpoint job that schedules events to a Mule component
  • Delegating Job - And outbound endpoint job that will schedule a job that is attached to the Mule Event.
  • Mule Client Dispatch Job - An outbound endpoint job that will dispatch the event on a given endpoint URI.
  • Mule Client Receiver Job - An outbound endpoint job that will perform a receive on an endpoint and then will dispatch the result over a different endpoint.

The following describes the configuration of each.

Mule Receiver Job

This is the Job used when an inbound quartz endpoint is configured on a component. It triggers an event to be received by the component based on the endpoint configuration.

A simple endpoint can be configured this way:

<endpoint address="quartz:/myService">
    <properties>
        <property name="repeatInterval" value="1000" />
        <property name="payloadClassName" value="com.foo.bar.Payload" />
    </properties>
</endpoint>

The same endpoint can also be expressed as a simple URI -

<endpoint address="quartz:/myService?repeatInterval=1000&amp;payloadClassName=com.foo.bar.Payload" />

Configuring the Payload of the Event

The payload can be set on the endpoint using the following mutually exclusive properties -

Property Description
payload The value of this property will be used
payloadRef A reference name to an object in a container context such as Jndi, Spring or Classloader container.

If neither of these properties are set an org.mule.providers.NullPayload will be used.

Mule Delegating Job

Extracts the Job object to invoke Mule Event that was dispatched to the quartz endpoint. The job can either be set as a property on
the event (this property can be a container reference or the actual job object) or the payload
of the event can be the Job, in which case when the job is fired the resulting event will have a org.mule.providers.NullPayload payload.

The following properties can be set on the MuleEvent before the event is dispatched to quartz -

Property Description
jobObject An instance of the Job to be invoked.
jobRef A reference name to a Job object in a container context such as Jndi, Spring or Classloader container.

If the Job is set as the payload of the event, these properties will be ignored and the DelegatingJob will be used automatically.

To explicitly configure the Delegating Job, you need to configure an outbound endpoint -

<endpoint name="schedulerEndpoint" address="quartz:/myService">
    <properties>
        <property name="jobClass" value="org.mule.providers.quartz.jobs.DelegatingJob"/>
        <property name="jobRef" value="com.foo.MyQuartzJob"/>
        <property name="repeatInterval" value="10000"/>
    </properties>
</endpoint>

Mule Client Dispatch Job

Can be used to schedule a one-off or repeated message dispatch to a Mule endpoint. To Configure this Job you add an outbound endpoint with the following configuration -

<endpoint name="schedulerEndpoint" address="quartz:/myService">
    <properties>
        <property name="jobClass" value="org.mule.providers.quartz.jobs.MuleClientDispatchJob"/>
        <property name="jobDispatchEndpoint" value="vm://service.X"/>
        <property name="repeatInterval" value="10000"/>
        <property name="repeatCount" value="5"/>
    </properties>
</endpoint>

The additional properties set are -

Property Description
jobClass The job class to schedule for execution.
jobDispatchEndpoint This is a property required by the org.mule.providers.quartz.jobs.MuleClientDispatchJob and specifies where to send the dispatch event

The event payload dispatched with be the same event that triggered the sheduling of the job. The payload will also be the same for each execution of the job. Usually, this Job will be used for one-off execution, to delay event delivery to a later date/time.

MuleClientReceiveJob

Is similar to the MuleClientDispatchJob but will first perform a receive on an endpoint before doing a dispatch. The dispatch will not happen if the receive yielded null.

<endpoint name="schedulerEndpoint" address="quartz:/myService">
    <properties>
        <property name="jobClass" value="org.mule.providers.quartz.jobs.MuleClientReceiveJob"/>
        <property name="jobReceiveEndpoint" value="jms://queue.X"/>
        <property name="jobReceiveTimeout" value="10000"/>
        <property name="jobDispatchEndpoint" value="vm://service.X"/>
        <property name="repeatInterval" value="10000"/>
    </properties>
</endpoint>

The configuration is the same as for MuleClientDispatchJob except there a couple of new parameters -

Property Description
jobReceiveEndpoint The endpoint URI (or endpoint identifier) that will be used to receive the event payload before doing a dispatch.
jobReceiveTimeout The number of milliseconds to wait on the receive before timing out the request and returning null.

Cron Expressions

A cron endpoint can be configured this way -

<endpoint address="quartz:/myService">
    <properties>
        <property name="cronExpression" value="0 0 2 * * ?" />
        ....
    </properties>
</endpoint>

The cronExpression property syntax is detailed here.

Quartz Scripting Example

Here is an example of using Quartz in conjunction with Groovy (thanks to Glenn Murry!)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mule-configuration PUBLIC "-//SymphonySoft //DTD mule-configuration XML V1.0//EN"
          "http://mule.mulesource.org/dtds/mule/mule-configuration.dtd">

<mule-configuration id="Script_Sample" version="1.0">
 <description>
  This Mule sample config shows how to use the Quartz provider to
  schedule a script.
 </description>

<!-- From www.stephenpasco.com -->
<global-endpoints>
 <endpoint name="quartz.in" address="quartz:/myService">
  <properties>
   <property name="repeatInterval" value="2000" />
   <property name="repeatCount" value="4" />
   <property name="startDelay" value="3000" />
   <property name="payloadClassName" value="" />
  </properties>
 </endpoint>
</global-endpoints>

<model name="sample">
 <mule-descriptor name="scriptRunner"
                  implementation="org.mule.components.script.jsr223.ScriptComponent"
                  inboundEndpoint="quartz.in">
  <properties>
   <property name="scriptEngineName" value="groovy"/>
    <text-property name="scriptText">
      println "Yo!"
    </text-property>
   </properties>
  </mule-descriptor>
 </model>

</mule-configuration>
Document generated by Confluence on Nov 27, 2006 10:27